<template>
  <div>
    <abnormal-dorm v-for="(item,index) in abnormalDormList" :key="index" :info="item"></abnormal-dorm>
  </div>

</template>

<script>
import AbnormalDorm from "../components/abnormal-dorm"
import { reversed_map } from "../common/building_mapper";
export default {
  name: "abnormal-dorm-list",
  components: {
    AbnormalDorm
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      const abnormalList = new Promise((resolve, reject) => {
        this.$api.abnormalList().then(res => {
          resolve(res)
        }).catch(err => {
          reject(err)
        })

      })
      /* TODO 这里可以适当优化 */
      abnormalList.then(res => {
        let abnormalList = res.data.data['abnormal']
        let updateTime = res.data.data['update_time']
        console.log(abnormalList, updateTime)
        this.$emit('abnormalListUpdateTime', updateTime)




        this.abnormalDormList = abnormalList.map(ele => {
          let buildingId = ele[0].split('-')[0]
          let roomId = ele[0].split('-')[1]

            return {
              dorm: reversed_map[buildingId] + roomId,
              score: eval(ele[1]).toFixed(2),
              /* TODO 项目时间紧迫 historyFee先写假数据 */
              // let buildingId = ele[0].split('-')[0]
              // let roomId = ele[0].split('-')[1]
              // this.$api.dormDataByDay(buildingId, roomId).then(res => {
              historyFee: (Math.random()*10+3).toFixed(2)
            }
          })




      })
    }
  },
  data() {
    return {
      abnormalDormList: [
        {
          dorm: "行健选四栋A102",
          historyFee: 130.0,
          score: 99
        },  {
          dorm: "行健选四栋A102",
          historyFee: 130.0,
          score: 99
        },  {
          dorm: "行健选四栋A102",
          historyFee: 130.0,
          score: 99
        },  {
          dorm: "行健选四栋A102",
          historyFee: 130.0,
          score: 99
        },  {
          dorm: "行健选四栋A102",
          historyFee: 130.0,
          score: 99
        }

      ]
    }
  }
};
</script>

<style scoped>

</style>